<?php
require_once APP . '/application/admincontrollers/AdminAction.php';
/**
 * 后台管理主页
 * @package admin
 */
class DictController extends AdminAction
{
    
	/**
	 * Enter description here...
	 *
	 * @var dict
	 */
	private $dict;
    public function init()
    {
    	require_once(APP . '/application/models/DictModel.php');
    	
        $this->dict = new DictModel($this->db);
    }


    /**
     * 加载框架页
     */
    public function addAction()
    {
        //加载默认视图
    }
    
    public function doaddAction()
    {
    	$params = $this->getAllParams();
    	
    	$this->dict->add($params);
    	
    	$this->view->msg = '添加成功';
    	$this->view->url = $this->url($this->view->baseUrl, "dict", "add", "", "admin");
    	$this->showmessage();
    }
    
    public function listAction()
    {
    	$nowp = (int) $this->getParam("nowp", 1);
    	$per_page = 20;
    	
    	$result = $this->dict->fetchAll($nowp, $per_page);
    	
    	$this->view->nowp = $nowp;
        $this->view->list = $result['list'];
        $this->view->page = $result['page'];
    }
    
    
    public function delAction()
    {
    	$did = (int) $this->getParam("did");
    	$nowp = (int) $this->getParam("nowp");
    	
    	$this->dict->del($did);
    	
    	header("location:" . $this->url($this->view->baseUrl, "dict", "list", "nowp=" . $nowp, "admin"));
    }
    
    
    public function editAction()
    {
    	$did = (int) $this->getParam("did");
    	$nowp = (int) $this->getParam("nowp");
    	
        $this->view->nowp = $nowp;
        $this->view->content = $this->dict->show($did);
    }
    
    public function doeditAction()
    {
    	$did = (int)$this->getParam("did");
    	$nowp = (int)$this->getParam("nowp");
    	$params = $this->getAllParams();
    	
    	$nowp = $this->getParam("nowp");
    	
    	$this->dict->change($did, $params);
    	
    	$this->view->msg = '编辑成功';
    	$this->view->url = $this->url($this->view->baseUrl, "dict", "list", "nowp=" . $nowp . '&group=' . $oldgroup, "admin");
    	$this->showmessage();
    }
    
    public function showAction()
    {
    	$did = (int)$this->getParam("did");
    	$this->view->content = $this->dict->show($did);
    }
}